<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\adminapi\controller\v1\car;

use app\adminapi\controller\AuthController;
use app\services\car\CarServiceServices;
use think\facade\App;

class CarService extends AuthController
{

    public function __construct(App $app,CarServiceServices $services)
    {
        parent::__construct($app);
        $this->services = $services;
    }

    /**
     * 获取列表
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getList() {
        $where = $this->request->getMore([
            ['keyword',''],//搜索条件
            ['status',0]
        ]);
        $list = $this->services->getList($where,'*','true');
        return app('json')->success($list);
    }

    /**
     * 获取表单
     * @param $id
     * @return mixed
     */
    public function add($id) {
        return app('json')->success($this->services->add((int)$id));
    }

    /**
     * 添加/修改
     * @return mixed
     */
    public function save() {
        $data = $this->request->postMore([
            ['id',''],
            ['name',''],
            ['remark',''],
            ['price',0],
            ['status',0]
        ]);
        return app('json')->success($this->services->save($data));
    }

    /**
     * 删除
     * @param $id
     * @return mixed
     */
    public function del($id) {
        return app('json')->success($this->services->del((int)$id));
    }

    /**
     * 状态
     * @param $id
     * @param $status
     * @return mixed
     */
    public function status($id,$status) {
        return app('json')->success($this->services->status((int)$id,(int)$status));
    }
}
